package com.xindacloud.sms.portal.handler;

import com.xindacloud.sms.portal.exception.RestTemplateException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//@ControllerAdvice
@Slf4j
public class SmsExceptionHandler extends ResponseEntityExceptionHandler {

    // @ExceptionHandler(value = RestTemplateException.class)
    public ResponseEntity<ErrorResponse> handleRestTemplateException(RestTemplateException ex, HttpServletRequest request, HttpServletResponse response) {
        log.error("An SmsException happened while calling {}  Remote API: {}", ex.getApi(), ex.toString());
        return new ResponseEntity<>(new ErrorResponse(ex, request.getRequestURI()), ex.getStatusCode());
    }
}
